class IUP_GET_TEXT
-- Shows a modal dialog to edit a multiline text. The text parameter must be 
-- large enough to contain the user input. The returned string is limited to 
-- maxsize characters.
--
-- The dialog uses a global attribute called "PARENTDIALOG" as the parent 
-- dialog if it is defined. It also uses a global attribute called "ICON" as 
-- the dialog icon if it is defined.

inherit
	IUP_WIDGET

create {ANY}
   get_text_with_initial

feature {ANY}

	get_text_with_initial (title, text: STRING; maxsize: INTEGER)
		-- Create a message box:
		--
		-- title: The dialog title.
		-- text: initial value of the text. It must have room for the edited 
		-- string with at least maxsize lenght.
		-- maxsize: the max size lenght.
		do
			create message.make(maxsize)

         message.append_string(text)
			ttl := title
			maxs := maxsize
		end

	launch: TUPLE[INTEGER, STRING]
		-- Show the dialog. Return a tuple with an integer, a non zero value if 
		-- the OK button is pressed, and the edited string.	
		local
			ms: STRING
			p: POINTER
			i: INTEGER
		do
			p := get_pointer(message.to_c)
			i := int_get_text (get_pointer(ttl.to_c), p, maxs)

			create ms.make_from_c(p)

			Result := [i, ms]
		end

feature {NONE}

	ttl, message: STRING
	maxs: INTEGER

	-- Internal
	
	int_get_text (title, text: POINTER; ms: INTEGER): INTEGER
		external
			"C inline use %"eiffel-iup.h%""
      alias
			"return IupGetText ($title, $text, $ms);"
      end

end -- end IUP_GET_TEXT

-- The MIT License (MIT)

-- Copyright (c) 2016, 2017, 2019 by German A. Arias

-- Permission is hereby granted, free of charge, to any person obtaining a copy
-- of this software and associated documentation files (the "Software"), to deal
-- in the Software without restriction, including without limitation the rights
-- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-- copies of the Software, and to permit persons to whom the Software is
-- furnished to do so, subject to the following conditions:
--
-- The above copyright notice and this permission notice shall be included in 
-- all copies or substantial portions of the Software.
--
-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
-- SOFTWARE.
